package com.zengge.zbc.controller;


import com.zengge.zbc.dto.Device;
import com.zengge.zbc.dto.Result;
import com.zengge.zbc.service.DeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

@RestController
@RequestMapping("/device")
public class DeviceController {

    private final DeviceService deviceService;

    @Autowired
    public DeviceController(DeviceService deviceService) {
        this.deviceService = deviceService;
    }

    @PostMapping("/saveOrUpdateDevice")
    public Result<String> saveOrUpdateDevice(@RequestBody Device device,
                                             @RequestAttribute("userId") long userId) {
        return Result.create(deviceService.saveOrUpdateDevice(device, userId));
    }

    @GetMapping("/deviceListGet")
    public Result<List<Device>> deviceListGet(@RequestParam("roomId") String roomId) {
        return Result.create(deviceService.deviceListGet(roomId));
    }

    @GetMapping("/deviceGet")
    public Result<Device> deviceGet(@RequestParam("deviceId") String deviceId) {
        return Result.create(deviceService.deviceGet(deviceId));
    }

    @GetMapping("/deviceDelete")
    public Result<Boolean> deviceDelete(@RequestParam("deviceId") String deviceId) {
        deviceService.deleteDevice(deviceId);
        return Result.create(true);
    }
}
